/*
 * TesterMain.h
 *
 *  Created on: Jan 7, 2011
 *      Author: dt
 */

#ifndef TESTERMAIN_H_
#define TESTERMAIN_H_

#include "talk/examples/monarch-common/XMPPCallback.h"
#include "talk/examples/monarch-common/ConnectionCallback.h"
#include "talk/examples/monarch-common/PipeEp.h"
#include "talk/base/thread.h"

class TesterMain: public XMPPCallback, public ConnectionCallback, public talk_base::Thread, public talk_base::MessageHandler
{
public:
  TesterMain(std::string& username, std::string& password,  std::string& xmppServerAddress, bool& debug, unsigned int& msgsize, unsigned int& msginterval);

  TesterMain(std::string& username, std::string& password,  std::string& xmppServerAddress, bool& debug , unsigned int& msgsize, unsigned int& msginterval,
          cricket::MediaEngine& mediaEngine,
          std::string& cmd_in, std::string& cmd_out);

  virtual void onRosterAdd(std::string& username);

  virtual void onChatMessageReceived(std::string& from, std::string& msg);

  virtual void onXmppConnected();

  virtual void sendCommands(void *threadid);

  virtual void handlePBUFMSG(char* pbuf, int len);

  virtual ConnectionCallback* onIncomingTunnelRequest();

  virtual void onTunnelConnect(PipeEp* p);

  virtual void onTunnelDisconnect(PipeEp* p, bool withError);

  virtual void onDataRecive(PipeEp* p, const char* buf, size_t size);

  // Override virtual method of parent MessageHandler. Context: Worker Thread.
  virtual void OnMessage(talk_base::Message* pmsg);



private:
  MonarchController *monarch_controller_;
  cricket::MediaEngine *media_engine_;
  PipeEp* pipe_;
  int video_pipe_,send_pipe_,rcv_pipe_;
  unsigned int msgsize_;
  unsigned int msginterval_;
  char read_buf_[1024*64];
  size_t read_buf_len_;
  char write_buf_[1024*64];
  size_t write_buf_len_;
  bool tunnel_connected_;
};



cricket::MediaEngine* CreateMonarchClientMediaEngine(const char* voice_in,
                                            const char* voice_out,
                                            const char* video_in,
                                            const char* video_out);
#endif /* TESTERMAIN_H_ */
